package com.mms.enumerate;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

public enum CodeEnum {
    success(0, "成功"),
    abnormal(-1, "异常"),
    SuccessfullyDeleted(0, "删除成功"),
    ModifiedSuccessfully(0, "修改成功"),
    noData(-1, "没有数据"),
    BeyondLimit(-1, "数组长度超出限制"),
    ProcessingFailed(-1, "处理失败"),
    ModificationFailed(-1, "修改失败"),
    okSignIn(0, "登录成功"),
    SignInFail(0, "登录失败"),
    notDoctor(-1, "不是医生"),
    AcquisitionFailed(-1, "获取失败"),
    noSignIn(-1, "没有登录");

    /**
     * 状态
     */
    private int code;
    /**
     * 提示
     */
    private String msg;

    CodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 自定义失败返回 msg
     *
     * @param msg
     * @return
     */
    public static String failMsg(String msg) {
        return failMsg(-1, msg);
    }

    public static String failMsg(Integer code, String msg) {
        JSONObject retJson = new JSONObject();
        retJson.put("code", code);
        retJson.put("msg", msg);
        return retJson.toString();
    }

    public String toString() {
        JSONObject retJson = new JSONObject();
        retJson.put("code", this.code);
        retJson.put("msg", this.msg);
        return retJson.toString();
    }

    public String toString(String msg) {
        JSONObject retJson = new JSONObject();
        retJson.put("code", this.code);
        retJson.put("msg", msg);
        return retJson.toString();
    }

    public String toString(Object obj) {
        JSONObject retJson = new JSONObject();
        retJson.put("code", this.code);
        retJson.put("msg", this.msg);
        retJson.put("data", obj);
        return retJson.toString();
    }

    public String toString(Object obj, long count) {
        JSONObject retJson = new JSONObject();
        retJson.put("code", this.code);
        retJson.put("msg", this.msg);
        retJson.put("data", obj);
        retJson.put("count", count);
        return retJson.toString(SerializerFeature.DisableCircularReferenceDetect);
    }

    public String toString(Object obj, Integer count) {
        return toString(obj, (long) count);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
